class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

/**
 * 2331. 计算布尔二叉树的值
 * https://leetcode.cn/problems/evaluate-boolean-binary-tree/description/
 */
class Solution {
    public boolean evaluateTree(TreeNode root) {
        if (root.left == null && root.right == null) return 0 == root.val ? false : true;

        boolean left = evaluateTree(root.left);
        boolean right = evaluateTree(root.right);

        return 2 == root.val ? left | right : left & right;
    }
}